//
//  BENewController.swift
//  New
//
//  Created by 李仁强 on 2016/9/30.
//  Copyright © 2016年 李仁强. All rights reserved.
//

import UIKit

private let newCellId = "newCellId"
//private let leftMargin : CGFloat = 226.0 / 750.0 * SCREEN_WIDTH
//private let rightMargin : CGFloat = leftMargin
//private let btmMargin : CGFloat = 182.0 / 1334.0 * SCREEN_HEIGHT

class BENewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate{

    var imagesArr : [String] = ["001", "002", "003", "004"]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    
    func setupUI() {
        //layout
        let layout = UICollectionViewFlowLayout()
        layout.itemSize = SCREEN_SIZE
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 0
        layout.scrollDirection = .horizontal
        
        //collection view
        let collectionView = UICollectionView(frame: SCREEN_BOUNDS, collectionViewLayout: layout)
        collectionView.backgroundColor = UIColor.white
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.register(UINib(nibName: "BENewCollectionCell", bundle: nil), forCellWithReuseIdentifier: newCellId)
        collectionView.isPagingEnabled = true
        collectionView.showsVerticalScrollIndicator = false
        collectionView.showsHorizontalScrollIndicator = false
        collectionView.bounces = false
        view = collectionView
    }
}

// collection view delegat function
extension BENewController {
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return imagesArr.count
    }
    
    @objc(collectionView:cellForItemAtIndexPath:) func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: newCellId, for: indexPath as IndexPath) as! BENewCollectionCell
        cell.picView.image = UIImage(named: imagesArr[indexPath.item])
        cell.enterButton.isHidden = true
        if indexPath.item == (imagesArr.count - 1) {
            cell.enterButton.isHidden = false
        }
        return cell
    }
}
